﻿Imports PTIC_Util
Imports System.Data.OleDb
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized

Public Class GeneriqueTypedParametre_EtatComputed(Of typeParametre)
    Inherits GeneriqueTypedParametre_EtatBase(Of typeParametre)
    Public Sub New(ByVal parametre As GeneriqueTypedParametre(Of typeParametre))
        MyBase.New(parametre)
    End Sub
    Public Overrides Sub MAJValeurs()
        If Not Parametre.Requete Is Nothing Then
            Parametre.Requete.Calculer_DataTable()
            Parametre.Valeurs = Parametre.Requete.DataTableResultat
        End If
    End Sub
    Public Overrides Sub onListeSegmentsChanged(ByVal sender As Object, ByVal e As System.Collections.Specialized.NotifyCollectionChangedEventArgs)
        If Not Parametre.Requete Is Nothing Then
            Select e.Action
                Case NotifyCollectionChangedAction.Add
                    Parametre.Requete.addGROUPBY(e.NewItems(0))
                Case NotifyCollectionChangedAction.Remove
                    Parametre.Requete.removeGROUPBY(e.OldItems(0))
                Case NotifyCollectionChangedAction.Reset
                    Parametre.Requete.ClearGROUPBY()
            End Select
        End If
    End Sub

    Public Overrides Sub Deserialize(ByVal param As GeneriqueTypedParametre(Of typeParametre))
        'Sauvegarde des caractéristiques actuelles du paramètre
        Dim AnciennesValeurs As DataTable = Me.Parametre.Valeurs.Copy
        Dim AnciensSegments As New Collection(Of String)
        For Each seg As String In Me.Parametre.ListeSegments
            AnciensSegments.Add(seg)
        Next

        'Alimentation des nouveaux segments du paramètre en fonction des valeurs sauvegardées
        Dim lSegments As ObservableCollection(Of String) = param.ListeSegments
        Me.Parametre.ListeSegments.Clear()
        For Each seg As String In lSegments
            Me.Parametre.ListeSegments.Add(seg)
        Next
        MAJValeurs()
    End Sub
End Class